/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package mod.dao;

import java.sql.ResultSet;

/**
 *
 * @author Sandrine KONGUEM
 */
public class tables extends connexion implements database{
    private String nom;
    private int id,blind,max,min;
    private int c1=0,c2=0,c3=0,c4=0,c5=0,c6=0,c7=0,c8=0,c9=0;
    private static String Table="tables";

    public tables() {
    }

    
    public tables(int id) {
        this.id = id;
    }

    public tables(String nom, int id, int blind, int max, int min) {
        this.nom = nom;
        this.id = id;
        this.blind = blind;
        this.max = max;
        this.min = min;
    }

    public tables(String nom, int id, int blind, int max, int min, int c1, int c2, int c3, int c4, int c5, int c6, int c7, int c8, int c9) {
        this.nom = nom;
        this.id = id;
        this.blind = blind;
        this.max = max;
        this.min = min;
        this.c1 = c1;
        this.c2 = c2;
        this.c3 = c3;
        this.c4 = c4;
        this.c5 = c5;
        this.c6 = c6;
        this.c7 = c7;
        this.c8 = c8;
        this.c9 = c9;
    }

    public static String getTable() {
        return Table;
    }

    public static void setTable(String Table) {
        tables.Table = Table;
    }

    public int getBlind() {
        return blind;
    }

    public void setBlind(int blind) {
        this.blind = blind;
    }

    public int getC(int v) {
        switch(v)
        {
            case 1: return c1;
            case 2: return c2;
            case 3: return c3;
            case 4: return c4;
            case 5: return c5;
            case 6: return c6;
            case 7: return c7;
            case 8: return c8;
            case 9: return c9;
            default: return 0;
        }
    }

    public void setC(int c,int v) {
        switch(c)
        {
            case 1: this.c1=v;break;
            case 2: this.c2=v;break;
            case 3: this.c3=v;break;
            case 4: this.c4=v;break;
            case 5: this.c5=v;break;
            case 6: this.c6=v;break;
            case 7: this.c7=v;break;
            case 8: this.c8=v;break;
            case 9: this.c9=v;break;
            default: break;
        }
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getMax() {
        return max;
    }

    public void setMax(int max) {
        this.max = max;
    }

    public int getMin() {
        return min;
    }

    public void setMin(int min) {
        this.min = min;
    }

    public String getNom() {
        return nom;
    }

    public void setNom(String nom) {
        this.nom = nom;
    }

    

    @Override
    public boolean equals(Object obj) {
        if(obj instanceof tables)
        {
            return ((tables) obj).getId()==this.getId();
        }
        return false;
    }

    @Override
    public String toString() {
        return getNom();
    }

    public int Creation()
    {
        int v=0;
        String req="insert into "+tables.Table+"(id,nom,blind,max,min,c1,c2,c3,c4,c5,c6,c7,c8,c9) " +
                "values("+getId()+",'"+getNom()+"',"+getBlind()+","+getMax()+","+getMin()+","+getC(1)+","+getC(2)+","+getC(3)+","+getC(4)+","+getC(5)+","+getC(6)+","+getC(7)+","+getC(8)+","+getC(9)+")";
        v= Req_LMD(req);
        if(v==0)
        {
            v=this.Modification();
        }
        return v;
    }

    public int Modification()
    {
        int v=0;
        String req="upatde "+tables.Table+" set " +
                "id ="+getId()+""+
                "nom ='"+getNom()+"'"+
                "blind ="+getBlind()+
                "max ="+getMax()+
                "min ="+getMin()+
                "c1 ="+getC(1)+
                "c2 ="+getC(2)+
                "c3 ="+getC(3)+
                "c4 ="+getC(4)+
                "c5 ="+getC(5)+
                "c6 ="+getC(6)+
                "c7 ="+getC(7)+
                "c8 ="+getC(8)+
                "c9 ="+getC(9)+
                "WHERE id="+getId();
        v= Req_LMD(req);
        return v;
    }

    public int Suppression() {
        int v=0;
        String req="delete from "+tables.Table+" where id="+getId();
        v= this.Req_LMD(req);
        return v;
    }

    public ResultSet Liste()
    {
        ResultSet r=null;
        String req="select * from "+tables.Table;
        r=Req_LID(req);
        return r;
    }

    public ResultSet Liste(int id)
    {
        ResultSet r=null;
        String req="select * from "+tables.Table+" where id="+id;
        r=Req_LID(req);
        return r;
    }
}
